package com.heima.controller;

import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.search.dtos.UserSearchDto;
import com.heima.model.vos.Result;
import com.heima.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author itheima
 * @since 2022-12-31
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping("/load")
    public Result load(@RequestBody ArticleHomeDto dto) {
        return Result.success(articleService.load(dto));
    }

    @PostMapping("/loadmore")
    public Result loadmore(@RequestBody ArticleHomeDto dto) {
        return Result.success(articleService.loadmore(dto));
    }

    @PostMapping("/loadnew")
    public Result loadnew(@RequestBody ArticleHomeDto dto) {
        return Result.success(articleService.loadnew(dto));
    }

    @PostMapping("/search/search")
    public Result search(@RequestBody UserSearchDto dto) throws IOException {
        return Result.success(articleService.searchArticle(dto));
    }

}
